package cn.edu.abtu.servlet;

import cn.edu.abtu.pojo.Student;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class StudentSecondServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        resp.setCharacterEncoding("UTF-8");
        //获取servlet传递过来的数据并在控制台打印
        Student student=(Student) req.getAttribute("student");
        System.out.println("学号："+student.getStuNo());
        System.out.println("姓名："+student.getStuName());
        System.out.println("学院："+student.getSchool());
        //向jsp传递对象类型的数据
        req.setAttribute("student",student);
        //传递字符串类型的数据
        req.setAttribute("college","aba teacher college");
        req.getRequestDispatcher("/student.jsp").forward(req,resp);
    }
}
